package com.hnucm.cooklife.ui.activity;

import static com.blankj.utilcode.util.ColorUtils.getColor;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.graphics.ColorUtils;

import com.bumptech.glide.Glide;
import com.hnucm.cooklife.R;
import com.hnucm.cooklife.base.BaseActivity;
import com.hnucm.cooklife.base.utils.LoginUtils;
import com.hnucm.cooklife.bean.db.User;
import com.hnucm.cooklife.contract.friends.Contract;
import com.hnucm.cooklife.presenter.friend.FriendPresenter;

import butterknife.BindView;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

public class FriendActivity extends BaseActivity<Contract.IFriendView, FriendPresenter> implements Contract.IFriendView {
    @BindView(R.id.friend_name)
    TextView friendName;

    @BindView(R.id.friend_header)
    CircleImageView friendHeader;

    @BindView(R.id.friend_bg)
    ImageView friendBg;

    @BindView(R.id.friend_follow)
    TextView friendFoll;

    private Context mContext;

    private int userId;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_friend;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        mContext = getApplicationContext();
        Intent intent = getIntent();
        userId = intent.getIntExtra("userId",0);

        mPresenter.loadFriend(this.userId);
        initStatusBar();
    }
    private void initStatusBar() {
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().setStatusBarColor(Color.WHITE);
        if (ColorUtils.calculateLuminance(getColor(R.color.white)) >= 0.5) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
    }


    @Override
    protected FriendPresenter createPresenter() {
        return new FriendPresenter();
    }

    @Override
    public void onLoading() {

    }

    @Override
    public void onLoadingFailed() {

    }

    @Override
    public void onLoadSuccess() {

    }

    @OnClick(R.id.friend_follow)
    public void click(){
        if(friendFoll.getText().equals("关注")){
            friendFoll.setText("已关注");
            friendFoll.setBackground(mContext.getDrawable(R.drawable.gray_shape));
        } else {
            friendFoll.setText("关注");
            friendFoll.setBackground(mContext.getDrawable(R.drawable.circle_shape));
        }
    }

    @Override
    public void onLoadFriend(User user) {
        friendName.setText(user.username);
        Glide.with(mContext)
                .load(user.icon)
                .into(friendHeader);

        Glide.with(mContext)
                .load(user.bg)
                .into(friendBg);
    }

    @Override
    public void onRefreshFriend(User user) {

    }
}
